<template>
  <div class="nav">
    <nav-bar>
      <div slot="left" class="back" @click="backClick">
        <img src="~assets/img/common/back.svg" alt="" />
      </div>

      <div slot="center" class="title">
        <div
          class="title-item"
          v-for="(item, index) in nav"
          :key="index"
          @click="titleAction(index)"
          :class="{ active: currentIndex === index }"
        >
          {{ item }}
        </div>
      </div>

      <div slot="right" class="right"></div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar.vue";

export default {
  components: {
    NavBar,
  },
  data() {
    return {
      nav: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    backClick() {
      this.$router.back();
    },

    titleAction(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
  },
};
</script>

<style scoped>
.title {
  display: flex;
  font-size: 13px;
    background-color: #f9f9f6;

}
.title-item {
  flex: 1;
}

.back img {
  margin-top: 10px;
}

.active {
  color: var(--color-high-text);
}

.nav .right {
    background-color: #f9f9f6;

}
</style>
